// JavaScript Document
function initialize() 
	{  
	console.log("hey");
		/*window.onbeforeunload = function() {
					  localStorage.removeItem('from');
					  localStorage.removeItem('to');
					  localStorage.removeItem('dist');		  
					  localStorage.removeItem('time');		  
					  return '';
					};
					directionsDisplay = new google.maps.DirectionsRenderer();
					
					var defaultBounds = new google.maps.LatLngBounds(
					new google.maps.LatLng(-33.8902, 151.1759),
					new google.maps.LatLng(-33.8474, 151.2631));*/
					
		localStorage.removeItem('hrs');
		localStorage.removeItem('mins');
			
        var curDate = new Date();
		console.log("Current date is: " + curDate);	
		//CURRENT DATE FORMAT- Wed Nov 13 2013 21:18:46 GMT+0530 (India Standard Time) 
			
		var timestamp = curDate.getTime();
	
		localStorage.setItem('ts', timestamp);
		var tslc = localStorage.getItem('ts');
		console.log("Timestamp is: " + tslc);
				
		var newdate = changecurdatetodatetimeformat(curDate);
		console.log("New date is: " + newdate);
		//NEW DATE FORMAT- 2013-11-13T21:18
		
		$('#timepicker').attr('value',newdate);
							
		var homelocalstoragechecker = window.localStorage.getItem('homeloc');

		if (homelocalstoragechecker == null) 
		{
    		$("a[name='usehomein-from']").addClass('ui-disabled');
			$("a[name='usehomein-to']").addClass('ui-disabled');
			$('#homelocationsaver').attr('placeholder','Location Name');
		} 
		else if (homelocalstoragechecker != null) 
		{
    		$("a[name='usehomein-from']").removeClass('ui-disabled');
			$("a[name='usehomein-to']").removeClass('ui-disabled');
		} 

		var worklocalstoragechecker = window.localStorage.getItem('workloc');

		if (worklocalstoragechecker == null) 
		{
    		$("a[name='useworkin-from']").addClass('ui-disabled');
			$("a[name='useworkin-to']").addClass('ui-disabled');
			$('#worklocationsaver').attr('placeholder','Location Name');
		} 
		else if (worklocalstoragechecker != null) 
		{
    		$("a[name='useworkin-from']").removeClass('ui-disabled');
			$("a[name='useworkin-to']").removeClass('ui-disabled');
		} 
		/*$("a[name='go']").removeClass('ui-btn-corner-all');
		$("a[name='go']").addClass('ui-btn-corner-all2');
		$("a[name='go']").removeClass('ui-btn-icon-notext');
		$("a[name='go']").addClass('ui-btn-icon-notext2'); 
		$("a[name='go']").removeClass('.ui-btn-icon-notext .ui-btn-inner .ui-icon');
		$("a[name='go']").addClass('.ui-btn-icon-notext1 .ui-btn-inner1 .ui-icon1');*/
		var options = {
        bounds: new google.maps.Circle({center:new google.maps.LatLng( 28.613889,77.208889 ),
                              radius:10000}).getBounds(),
        //types:  ['geocode'],
		componentRestrictions: { country: 'IN' }
        
    };
		var input1 = document.getElementById('from');
		var autocomplete1 = new google.maps.places.Autocomplete(input1,options);
		var input2 = document.getElementById('to');
		var autocomplete2 = new google.maps.places.Autocomplete(input2,options);
		var gethomeloc = document.getElementById('homelocationsaver');
		var autocomplete3 = new google.maps.places.Autocomplete(gethomeloc,options);
		var sethomeloc = document.getElementById('worklocationsaver');
		var autocomplete4 = new google.maps.places.Autocomplete(sethomeloc,options);
		
	}
	
function changecurdatetodatetimeformat(curDate)
{
	var Datesplitted = curDate.toString().split(" ");

	var month;
	if (Datesplitted[1] == "Jan") {month = '01';}
	else if (Datesplitted[1] == "Feb") {month = '02';}
	else if (Datesplitted[1] == "Mar") {month = '03';}
	else if (Datesplitted[1] == "Apr") {month = '04';}
	else if (Datesplitted[1] == "May") {month = '05';}
	else if (Datesplitted[1] == "Jun") {month = '06';}
	else if (Datesplitted[1] == "Jul") {month = '07';}
	else if (Datesplitted[1] == "Aug") {month = '08';}
	else if (Datesplitted[1] == "Sep") {month = '09';}
	else if (Datesplitted[1] == "Oct") {month = '10';}
	else if (Datesplitted[1] == "Nov") {month = '11';}
	else if (Datesplitted[1] == "Dec") {month = '12';}
	
	var time = Datesplitted[4];
	var timesplitted = time.split(":");
	var hrs = timesplitted[0];
	var mins = timesplitted[1];		

	localStorage.setItem('hrs', hrs);
	localStorage.setItem('mins',mins);
		
	var newdate = Datesplitted[3]+"-"+month+"-"+Datesplitted[2]+"T"+hrs+":"+mins;
	
	return newdate;
}

function timesaver(){
	var userinput = $('input[name=timepicker]').val();
	console.log("User input is: " + userinput);
	//USER INPUT FORMAT- 2013-11-13T22:18
	
	var myDate = new Date (userinput);
	console.log("User input stored as a date variable is: " + myDate);
	//USER INPUT STORED AS DATE VARIABLE FORMAT- Thu Nov 14 2013 03:48:00 GMT+0530 (India Standard Time) 
	
	var Datesplitted = myDate.toString().split(" ");
	var time = Datesplitted[4];
	var timesplitted = time.split(":");
	var hrs = timesplitted[0];
	var mins = timesplitted[1];
	
	localStorage.setItem('hrs', hrs);
	localStorage.setItem('mins',mins);
	//var splitteddate = myDate.split(" ");
	//console.log("Date splitted is: " + Datesplitted);
	console.log("Time is: " + time);
	//console.log("Time splitted is: " + timesplitted);
	console.log("Hours: " + hrs);
	console.log("Minutes: " + mins);
	
	var timestamp = myDate.getTime();
	
	localStorage.setItem('ts', timestamp);
	var tslc = localStorage.getItem('ts');
	console.log("Timestamp is: " + tslc);
}
